Page({
    data: {
        wrongQuestions: []
    },
    onLoad: function () {
        // // 获取错题集数据
        // const pages = getCurrentPages();
        // const currentPage = pages[pages.length - 2];
        // this.setData({
        //     wrongQuestions: currentPage.data.wrongQuestions
        // });

        this.loadWrongQuestions();
    },
    onShow: function () {
        this.loadWrongQuestions();  // 页面显示时重新加载错题集，确保删除后的数据是最新的
    },
    loadWrongQuestions: function () {
        const wrongQuestions = wx.getStorageSync('wrongQuestions') || [];
        this.setData({ wrongQuestions });
    },
    goBack: function () {
        // 返回上一页（index页面）
        wx.navigateBack({
            delta: 1
        });
    },
    deleteQuestion: function (e) {
        const index = e.currentTarget.dataset.index;
        let updatedQuestions = [...this.data.wrongQuestions];
        // 删除指定的错题
        updatedQuestions.splice(index, 1);
        // 更新页面的错题集
        this.setData({ wrongQuestions: updatedQuestions });
        // 将更新后的错题集保存到本地存储
        wx.setStorageSync('wrongQuestions', updatedQuestions);
    }
});
